package baseFx.common.context;

import baseFx.common.Action1T;
import baseFx.common.Func;

import java.util.List;

public interface TypeResolver extends AutoCloseable {
    TypeResolver root();

    TypeResolver sub(BeanDef... params);

    void register(BeanDef def);

    <T> T resolve(Class<T> clazz);

    List<Class<?>> getClassListForType(Class<?> clazz);

    @Override
    void close();

    default void register(Action1T<BeanDef> action) {
        BeanDef def = new BeanDef();
        action.execute(def);
        register(def);
    }

    default TypeResolver sub(Func<BeanDef[]> func) {
        return sub(func.execute());
    }

    default TypeResolver sub(Action1T<BeanDef> func) {
        BeanDef p = new BeanDef();
        func.execute(p);
        return sub(p);
    }
}
